package com.quktzhuanka.app.fragments;

import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.gcssloop.widget.PagerGridLayoutManager;
import com.gcssloop.widget.PagerGridSnapHelper;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import com.quktzhuanka.app.activity.WebViewActivityt;
import com.quktzhuanka.app.activity.WebViewActivityz;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import com.uuch.adlibrary.AdConstant;
import com.uuch.adlibrary.AdManager;
import com.uuch.adlibrary.bean.AdInfo;
import com.quktzhuanka.app.CaiNiaoApplication;
import com.quktzhuanka.app.R;
import com.quktzhuanka.app.activity.BaoYouActivity;
import com.quktzhuanka.app.activity.CommissionPhbActivity;
import com.quktzhuanka.app.activity.DailyBonusActivity;
import com.quktzhuanka.app.activity.DouActivity;
import com.quktzhuanka.app.activity.JdActivity;
import com.quktzhuanka.app.activity.NewClassActivity;
import com.quktzhuanka.app.activity.NewsActivity;
import com.quktzhuanka.app.activity.PHBActivity;
import com.quktzhuanka.app.activity.PddActivity;
import com.quktzhuanka.app.activity.PinPaiActivity;
import com.quktzhuanka.app.activity.PromotionDetailsActivity;
import com.quktzhuanka.app.activity.QdActivity;
import com.quktzhuanka.app.activity.SearchActivity;
import com.quktzhuanka.app.activity.ShopActivity;
import com.quktzhuanka.app.activity.ShopMallActivity;
import com.quktzhuanka.app.activity.SysMessageActivity;
import com.quktzhuanka.app.activity.TqgNewActivity;
import com.quktzhuanka.app.activity.WebViewActivity;
import com.quktzhuanka.app.activity.WebViewActivity2;
import com.quktzhuanka.app.activity.WebViewActivity3;
import com.quktzhuanka.app.activity.ZeroBuyActivity;
import com.quktzhuanka.app.adapter.HomeIconAdapter;
import com.quktzhuanka.app.adapter.IndexCatAdapter;
import com.quktzhuanka.app.adapter.TodayHighlightsAdapter;
import com.quktzhuanka.app.adapter.TodayHighlightsChildAdapter2;
import com.quktzhuanka.app.base.BaseLazyFragment;
import com.quktzhuanka.app.bean.BannerBean;
import com.quktzhuanka.app.bean.HaoDanBean;
import com.quktzhuanka.app.bean.MessageCenterBean;
import com.quktzhuanka.app.bean.PddClient;
import com.quktzhuanka.app.bean.Response;
import com.quktzhuanka.app.bean.SetBean;
import com.quktzhuanka.app.bean.ShopTabsBean;
import com.quktzhuanka.app.bean.ShopTabsChildBean;
import com.quktzhuanka.app.bean.TaobaoGuestBean;
import com.quktzhuanka.app.bean.TodayHighlightsBean2;
import com.quktzhuanka.app.bean.UserInfoBean;
import com.quktzhuanka.app.common.CommonUtils;
import com.quktzhuanka.app.common.SPUtils;
import com.quktzhuanka.app.common.T;
import com.quktzhuanka.app.config.Constants;
import com.quktzhuanka.app.https.HttpUtils;
import com.quktzhuanka.app.https.onOKJsonHttpResponseHandler;
import com.quktzhuanka.app.utils.CornerTransform;
import com.quktzhuanka.app.utils.ScrollBanner;
import com.quktzhuanka.app.utils.UIUtils;
import com.quktzhuanka.app.widget.indicator.MagicIndicator;
import com.quktzhuanka.app.widget.indicator.buildins.commonnavigator.CommonNavigator;
import com.quktzhuanka.app.widget.indicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import com.quktzhuanka.app.widget.indicator.buildins.commonnavigator.abs.IPagerIndicator;
import com.quktzhuanka.app.widget.indicator.buildins.commonnavigator.abs.IPagerTitleView;
import com.quktzhuanka.app.widget.indicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import com.quktzhuanka.app.widget.indicator.buildins.commonnavigator.titles.ClipPagerTitleView;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;
import com.youth.banner.transformer.ZoomOutTranformer;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import cz.msebera.android.httpclient.Header;

import static com.quktzhuanka.app.bean.PddClient.stringToMD5;

/**
 * 首页
 * Created by yohn on 2018/7/11.
 */

public class HomeFragment extends BaseLazyFragment implements View.OnClickListener {

    TextView tv_title_content;
    MagicIndicator tabBar;
    @BindView(R.id.tabBar2)
    MagicIndicator tabBar2;
    @BindView(R.id.img_more2)
    CheckBox imgMore2;
    CheckBox imgMore;
    @BindView(R.id.bg_head2)
    LinearLayout bgHead2;
    @BindView(R.id.lay_more)
    RecyclerView layMore;
    @BindView(R.id.right_icon)
    ImageView rightIcon;
    LinearLayout bgHead;
    private View view;
    public static HomeFragment fragment;
    private ImageView homeBg;
    //导航标题
    private List<ShopTabsChildBean> tabTitles = new ArrayList<>();
    @BindView(R.id.home_recyclerView)
    RecyclerView homeRecyclerView;
    Unbinder unbinder;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;
    private String min_id = "1";
    IndexCatAdapter indexCatAdapter;
    private List<TodayHighlightsBean2> todayHighlightsBeans = new ArrayList<>();
    private List<HaoDanBean> todayHighlightsBeans2 = new ArrayList<>();
    private TodayHighlightsAdapter highlightsAdapter;
    private TodayHighlightsChildAdapter2 highlightsAdapter2;
    private RecyclerView homeGrid;
    private int Home_Search = 0; //0为首页,1为搜索页

    private String search_content;//搜索内容

    private String search_sort;//排序字段

    private boolean has_coupon = true;//是否优惠券

    private int indexNum = 1;

    private int refreshStatus = 0;

    List<HaoDanBean> taobaoGuesChildtBeans = new ArrayList<>();
    private LinearLayoutManager linearLayoutManager;
    private Banner banner;
    private MZBannerView banner2;
    private ScrollBanner scrollBanner;
    private List<BannerBean> images3 = new ArrayList<>();
    private List<BannerBean> images = new ArrayList<>();
    private List<MessageCenterBean.MessageCenterChildBean> images2 = new ArrayList<>();
    private HomeIconAdapter homeIconAdapter;
    private List<SetBean.Item> homeItems = new ArrayList<>();
    private RadioButton rb1, rb2, rb3, rb4, rb5, rb6;
    private RadioGroup page_rg;
    private TextView txt1, txt2, txt3;
    @BindView(R.id.img_head2)
    ImageView imgHead2;
    private ImageView imgHead;
    //    private RecyclerView tuijianRecy, baoyouRecy, qgRecy;
    List<TaobaoGuestBean.TaobaoGuesChildtBean> nineList = new ArrayList<>();
    //    private NineAdapter nineAdapter;
//    private PHBAdapter phbAdapter;
    DecimalFormat df = new DecimalFormat("0.00");
    //    private List<HaoDanBean> list = new ArrayList<>();
//    private List<HaoDanBean> qgList = new ArrayList<>();
//    private TextView txtHour, tipTwo, tipThree;
//    private HomeQGAdapter homeQGAdapter;
    Date endTime;
    RadioGroup rg_index;
    private GridView gridView;
    int hour_type = 1;
    String phone = "18866666666";
    String jiayou = "";
    private UserInfoBean userBean;

    public static HomeFragment getInstance() {
        if (fragment == null) {
            fragment = new HomeFragment();
        }
        return fragment;
    }

    private static boolean flag = true;
    private boolean hasdata = true;
    private Gson gson = new Gson();
    DateFormat df_date = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home, container, false);
        ButterKnife.bind(this, view);
        bgHead2.measure(0, 0);
        init();
        addListener();
        isVisible = true;
        lazyload();
        return view;
    }

    private void setTimer() {
        Message message = mHandler.obtainMessage(999);     // Message
        mHandler.sendMessageDelayed(message, 1000);
    }

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case 999:
                    //在这里去执行定时操作逻辑
                    if (flag) {
                        long diff = endTime.getTime() - new Date().getTime();
                        long days = diff / (1000 * 60 * 60 * 24);
                        long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);
                        long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
                        long secs = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60) - minutes * (1000 * 60)) / (1000);
                        txt1.setText("0" + hours + "");
                        txt2.setText(minutes < 10 ? "0" + minutes : minutes + "");
                        txt3.setText(secs < 10 ? "0" + secs : secs + "");
                        Message message = mHandler.obtainMessage(999);
                        mHandler.sendMessageDelayed(message, 1000);
                    }
                    break;
                default:
                    break;
            }
        }
    };

    private void stopTimer() {
        flag = false;
    }

    private void init() {
        highlightsAdapter2 = new TodayHighlightsChildAdapter2(context, R.layout.index_item, todayHighlightsBeans2);   // 限时秒杀
        highlightsAdapter = new TodayHighlightsAdapter(R.layout.today_highlights_item, todayHighlightsBeans);   // 为你推荐
        linearLayoutManager = new LinearLayoutManager(getActivity());
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        homeRecyclerView.setLayoutManager(linearLayoutManager);
        layMore.setLayoutManager(new GridLayoutManager(context,5));
        indexCatAdapter=new IndexCatAdapter(R.layout.item_index_cat_text,tabTitles);
        layMore.setAdapter(indexCatAdapter);
        indexCatAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(getActivity(), ShopActivity.class);
                intent.putExtra("title", "商品");
                intent.putExtra("index", position);
                intent.putExtra("name", "");
                startActivity(intent);
            }
        });
        view.findViewById(R.id.right_icon).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                homeRecyclerView.post(new Runnable() {
                    @Override
                    public void run() {
                        homeRecyclerView.smoothScrollToPosition(0);
                    }
                });
            }
        });
        //设置一个头部
        View homeTabView = getLayoutInflater().inflate(R.layout.home_tab_layout, null);
        tv_title_content = homeTabView.findViewById(R.id.tv_title_content);
        tv_title_content.setOnClickListener(this);
        tabBar = homeTabView.findViewById(R.id.tabBar);
        banner = homeTabView.findViewById(R.id.main_banner);
//        banner.setLayoutParams(new RelativeLayout.LayoutParams(BitmapUtils.getScreenWith(context), (int) (BitmapUtils.getScreenWith(context) / 2.3)));
        banner.setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                if (context != null && !((Activity) context).isDestroyed())
                    Glide.with(context).load(path).asBitmap().skipMemoryCache(false).dontAnimate().error(R.drawable.no_banner).transform(new CornerTransform(context, 10)).into(imageView);
            }

        });
        banner2 = homeTabView.findViewById(R.id.home_ad);
        homeBg = homeTabView.findViewById(R.id.home_bg);
        rg_index = homeTabView.findViewById(R.id.rg_index);
        banner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        banner.setIndicatorGravity(BannerConfig.RIGHT);
        scrollBanner = homeTabView.findViewById(R.id.main_scroll);
        RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        homeTabView.setLayoutParams(layoutParams);
        rb1 = homeTabView.findViewById(R.id.rb_one);
        gridView = homeTabView.findViewById(R.id.listView1);
        gridView.setAdapter(highlightsAdapter2);
        rb2 = homeTabView.findViewById(R.id.rb_two);
        imgHead = homeTabView.findViewById(R.id.img_head);
        imgMore=homeTabView.findViewById(R.id.img_more);
        rb3 = homeTabView.findViewById(R.id.rb_three);
        rb4 = homeTabView.findViewById(R.id.rb_four);
        rb5 = homeTabView.findViewById(R.id.rb_five);
        rb6 = homeTabView.findViewById(R.id.rb_six);
        txt1 = homeTabView.findViewById(R.id.txt_hour);
        txt2 = homeTabView.findViewById(R.id.txt_minutes);
        txt3 = homeTabView.findViewById(R.id.txt_sec);
        Calendar ca = Calendar.getInstance();
        int hour = ca.get(Calendar.HOUR_OF_DAY);//小时
        int year = ca.get(Calendar.YEAR);//获取年份
        int month = ca.get(Calendar.MONTH) + 1;//获取月份
        int day = ca.get(Calendar.DATE);//获取日
        Log.d("dfasdf", year + "" + month + day);

        if (hour < 10) {
            hour_type = 6;
            rb1.setText(String.format(getResources().getString(R.string.test_text), "00:00", "抢购中"));
            rb1.setChecked(true);
            try {
                endTime = df_date.parse(year + "-" + month + "-" + day +" 10:00:00");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            rb1.setTextColor(getResources().getColor(R.color.white));
            rb2.setText(String.format(getResources().getString(R.string.test_text), "10:00", "即将开始"));
            rb3.setText(String.format(getResources().getString(R.string.test_text), "12:00", "即将开始"));
            rb4.setText(String.format(getResources().getString(R.string.test_text), "15:00", "即将开始"));
            rb5.setText(String.format(getResources().getString(R.string.test_text), "20:00", "即将开始"));
            rb6.setText(String.format(getResources().getString(R.string.test_text), "24:00", "即将开始"));
        } else if (hour < 12) {
            hour_type = 7;

            rb1.setText(String.format(getResources().getString(R.string.test_text), "00:00", "已结束"));
            rb2.setChecked(true);
            try {
                endTime = df_date.parse(year + "-" + month + "-" + day + " 12:00:00");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            rb2.setTextColor(getResources().getColor(R.color.white));
            rb2.setText(String.format(getResources().getString(R.string.test_text), "10:00", "抢购中"));
            rb3.setText(String.format(getResources().getString(R.string.test_text), "12:00", "即将开始"));
            rb4.setText(String.format(getResources().getString(R.string.test_text), "15:00", "即将开始"));
            rb5.setText(String.format(getResources().getString(R.string.test_text), "20:00", "即将开始"));
            rb6.setText(String.format(getResources().getString(R.string.test_text), "24:00", "即将开始"));
        } else if (hour < 15) {
            hour_type = 8;

            rb1.setText(String.format(getResources().getString(R.string.test_text), "00:00", "已结束"));
            rb3.setChecked(true);
            rb3.setTextColor(getResources().getColor(R.color.white));
            try {
                endTime = df_date.parse(year + "-" + month + "-" + day + " 15:00:00");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            rb2.setText(String.format(getResources().getString(R.string.test_text), "10:00", "已结束"));
            rb3.setText(String.format(getResources().getString(R.string.test_text), "12:00", "抢购中"));
            rb4.setText(String.format(getResources().getString(R.string.test_text), "15:00", "即将开始"));
            rb5.setText(String.format(getResources().getString(R.string.test_text), "20:00", "即将开始"));
            rb6.setText(String.format(getResources().getString(R.string.test_text), "24:00", "即将开始"));
        } else if (hour < 20) {
            hour_type = 9;

            rb1.setText(String.format(getResources().getString(R.string.test_text), "00:00", "已结束"));
            rb4.setChecked(true);
            rb4.setTextColor(getResources().getColor(R.color.white));
            rb2.setText(String.format(getResources().getString(R.string.test_text), "10:00", "已结束"));
            try {
                endTime = df_date.parse(year + "-" + month + "-" + day + " 20:00:00");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            rb3.setText(String.format(getResources().getString(R.string.test_text), "12:00", "已结束"));
            rb4.setText(String.format(getResources().getString(R.string.test_text), "15:00", "抢购中"));
            rb5.setText(String.format(getResources().getString(R.string.test_text), "20:00", "即将开始"));
            rb6.setText(String.format(getResources().getString(R.string.test_text), "24:00", "即将开始"));
        } else if (hour < 24) {
            hour_type = 10;

            rb1.setText(String.format(getResources().getString(R.string.test_text), "00:00", "已结束"));
            rb5.setChecked(true);
            try {
                endTime = df_date.parse(year + "-" + month + "-" + day + " 24:00:00");
            } catch (ParseException e) {
                e.printStackTrace();
            }
            rb5.setTextColor(getResources().getColor(R.color.white));
            rb2.setText(String.format(getResources().getString(R.string.test_text), "10:00", "已结束"));
            rb3.setText(String.format(getResources().getString(R.string.test_text), "12:00", "已结束"));
            rb4.setText(String.format(getResources().getString(R.string.test_text), "15:00", "已结束"));
            rb5.setText(String.format(getResources().getString(R.string.test_text), "20:00", "抢购中"));
            rb6.setText(String.format(getResources().getString(R.string.test_text), "24:00", "即将开始"));
        }
        setTimer();
        getTbkListRequst1(search_sort, "必推精选", "服装");
        rg_index.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rb_one:
                        hour_type = 6;
                        min_id = "1";
                        getTbkListRequst1(search_sort, "必推精选", "服装");
                        break;
                    case R.id.rb_two:
                        hour_type = 7;
                        min_id = "1";
                        getTbkListRequst1(search_sort, "必推精选", "服装");
                        break;
                    case R.id.rb_three:
                        hour_type = 8;
                        min_id = "1";
                        getTbkListRequst1(search_sort, "必推精选", "服装");
                        break;
                    case R.id.rb_four:
                        hour_type = 9;
                        min_id = "1";
                        getTbkListRequst1(search_sort, "必推精选", "服装");
                        break;
                    case R.id.rb_five:
                        hour_type = 10;
                        min_id = "1";
                        getTbkListRequst1(search_sort, "必推精选", "服装");
                        break;
                    case R.id.rb_six:
                        hour_type = 11;
                        min_id = "1";
                        getTbkListRequst1(search_sort, "必推精选", "服装");
                        break;


                }
            }
        });
        //优惠转
        homeTabView.findViewById(R.id.ll_home_one).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_two).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_three).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_four).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_one1).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_two1).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_three1).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_four1).setOnClickListener(this);
        homeTabView.findViewById(R.id.tv_right).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_five).setOnClickListener(this);
        homeTabView.findViewById(R.id.ll_home_six).setOnClickListener(this);
//        homeTabView.findViewById(R.id.txt_cj).setOnClickListener(this);
        bgHead = homeTabView.findViewById(R.id.bg_head);
        homeGrid = homeTabView.findViewById(R.id.home_grid);
//        homeTabView.findViewById(R.id.img_zero).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                openActivity(ZeroBuyActivity.class);
//            }
//        });
//        homeTabView.findViewById(R.id.img_new).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                openActivity(NewClassActivity.class);
//            }
//        });

//        homeTabView.findViewById(R.id.ll_zero).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                openActivity(ZeroBuyActivity.class);
//            }
//        });
//        homeTabView.findViewById(R.id.ll_jd).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                openActivity(JdActivity.class);
//            }
//        });
//        homeTabView.findViewById(R.id.ll_qg).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                openActivity(TqgNewActivity.class);
//            }
//        });
//        homeTabView.findViewById(R.id.ll_pdd).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                openActivity(PddActivity.class);
//            }
//        });
       /* homeTabView.findViewById(R.id.ll_phb).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openActivity(PHBActivity.class);
            }
        });*/
        // 1.水平分页布局管理器
        PagerGridLayoutManager layoutManager = new PagerGridLayoutManager(
                3, 5, PagerGridLayoutManager.HORIZONTAL);
        layoutManager.setPageListener(new PagerGridLayoutManager.PageListener() {
            @Override
            public void onPageSizeChanged(int pageSize) {
            }

            @Override
            public void onPageSelect(int pageIndex) {
                page_rg.check(pageIndex);
            }
        });
        page_rg = homeTabView.findViewById(R.id.page_rg);
        layoutManager.setChangeSelectInScrolling(true);
        homeGrid.setLayoutManager(layoutManager);
// 2.设置滚动辅助工具

        PagerGridSnapHelper pageSnapHelper = new PagerGridSnapHelper();
        pageSnapHelper.attachToRecyclerView(homeGrid);
//        homeGrid.setLayoutManager(new GridLayoutManager(context, 4));
        homeIconAdapter = new HomeIconAdapter(context, R.layout.service_home_grid_item, homeItems);
        homeGrid.setAdapter(homeIconAdapter);
        homeIconAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                Intent intent;
//               外链自定义    天  2020-5-12 19:21:39
                if ("Y".equals(homeItems.get(position).is_url_show)){
                    switch (homeItems.get(position).id) {
                        case "34":
                            intent = new Intent(context, WebViewActivity3.class);
                            intent.putExtra("title", homeItems.get(position).name);
                            intent.putExtra("url", jiayou+phone);
                            startActivity(intent);
                            break;
                        case "35":
                            String smd5 = stringToMD5(phone+"yq002952%4++i7|");
                            intent = new Intent(context, WebViewActivity3.class);
                            intent.putExtra("title", homeItems.get(position).name);
                            intent.putExtra("url", "https://c.buuyee.com/api/external?channel=yq00295&signature="+smd5+"&time="+new Date()+"&phone="+phone);
                            startActivity(intent);
                            break;
//                        case "28":
//                            intent = new Intent(context, WebViewActivityt.class);
//                            intent.putExtra("title", homeItems.get(position).name);
//                            intent.putExtra("url", homeItems.get(position).url);
//                            intent.putExtra("cid", homeItems.get(position).id);
//                            startActivity(intent);
//                            break;
                        default:
                            intent = new Intent(context, WebViewActivity.class);
                            intent.putExtra("title", homeItems.get(position).name);
                            intent.putExtra("url", homeItems.get(position).url);
                            startActivity(intent);
                            break;
                    }

                }else{
                    switch (homeItems.get(position).id) {
                        case "1":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "20");
                            startActivity(intent);
                            break;
                        case "2":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "9");
                            startActivity(intent);
                            break;
                        case "3":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "2");
                            startActivity(intent);
                            break;
                        case "4":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "5");
                            startActivity(intent);
                            break;
                        case "5":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "4");
                            startActivity(intent);
                            break;
                        case "6":
                            intent = new Intent(context, WebViewActivity3.class);
                            intent.putExtra("title", "天猫超市");
                            intent.putExtra("url", "https://chaoshi.tmall.com/?targetPage=index");
                            startActivity(intent);
                            break;
                        case "7":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "1");
                            startActivity(intent);
                            break;
                        case "8":
                            openActivity(PHBActivity.class);
                            break;
                        case "9":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "22");
                            startActivity(intent);
                            break;
                        case "10":
                            openActivity(PddActivity.class);
                            break;
                        case "11":
                            openActivity(JdActivity.class);
                            break;
                        case "12":
                            openActivity(ShopMallActivity.class);
                            break;
                        case "13":
                            openActivity(NewClassActivity.class);
                            break;
                        case "14":
                            intent = new Intent(context, WebViewActivity.class);
                            intent.putExtra("title", "拉新活动");
                            intent.putExtra("url", Constants.APP_IP + "/wap.php/Rookie/index/uid/" + SPUtils.getStringData(context, Constants.UID, ""));
                            startActivity(intent);
                            break;
                        case "15":
                            openActivity(ZeroBuyActivity.class);
                            break;
                        case "16":
                            hongbao();
                            break;
                        case "17":
                            openActivity(DailyBonusActivity.class);
                            break;
                        case "18":
                            break;
                        case "19":
                            intent = new Intent(getActivity(), BaoYouActivity.class);
                            intent.putExtra("type", "23");
                            startActivity(intent);
                            break;
                        case "20":
                            intent = new Intent(context, WebViewActivity3.class);
                            intent.putExtra("title", "天猫国际");
                            intent.putExtra("url", "https://pages.tmall.com/wow/jinkou/act/zhiyingchaoshi?from=zebra:offline");
                            startActivity(intent);
                            break;
                        case "21":
                            openActivity(PinPaiActivity.class);
                            break;
                        case "22":
                            intent = new Intent(context, WebViewActivity3.class);
                            intent.putExtra("title", "生活券");
                            intent.putExtra("url", "http://www.quanmama.com/t/couponExport/couponList.aspx?categoryid=5475");
                            startActivity(intent);
                            break;
                        case "23":
                            intent = new Intent(context, DailyBonusActivity.class);
                            startActivity(intent);
                            break;
                        case "24":
                            intent = new Intent(context, CommissionPhbActivity.class);
                            startActivity(intent);
                            break;
                        case "25":
                            intent = new Intent(context, WebViewActivity3.class);
                            intent.putExtra("title", "天猫美妆");
                            intent.putExtra("url", "https://meizhuang.tmall.com");
                            startActivity(intent);
                            break;
                        case "26":
                            intent = new Intent(context, WebViewActivity3.class);
                            intent.putExtra("title", "飞猪旅行");
                            intent.putExtra("url", "https://s.click.taobao.com/la0wrlv");
                            startActivity(intent);
                            break;
                        case "27":
                            Bundle bundle = new Bundle();
                            bundle.putString("id", "0");
                            openActivity(DouActivity.class, bundle);
                            break;
                        case "28":
                            intent = new Intent(context, WebViewActivityz.class);
                            intent.putExtra("title", homeItems.get(position).name);
                            intent.putExtra("url", Constants.GET_ZHUANKA_URL);
                            startActivity(intent);
                            break;
                        case "36":
                            intent = new Intent(context, WebViewActivityz.class);
                            intent.putExtra("title", homeItems.get(position).name);
                            intent.putExtra("url", Constants.GET_ZHUANKA_HALL);
                            startActivity(intent);
                            break;
                    }
                }

            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
//        getIndexIcon();
        getUserMsg();
        highlightsAdapter.addHeaderView(homeTabView);
        homeRecyclerView.setAdapter(highlightsAdapter);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
//                refreshLayout.autoRefresh();
                getIndexIcon();
                getBanner();
                getAD();
                getHomeADimg();
            }
        }, 200);
        imgMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imgMore2.setChecked(imgMore.isChecked());
                if(imgMore.isChecked()){
                    layMore.setVisibility(View.VISIBLE);
                }else{
                    layMore.setVisibility(View.GONE);
                }
            }
        });
        imgMore2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                imgMore.setChecked(imgMore2.isChecked());
                if(imgMore2.isChecked()){
                    layMore.setVisibility(View.VISIBLE);
                }else{
                    layMore.setVisibility(View.GONE);
                }
            }
        });
    }

    class BannerViewHolder implements MZViewHolder<String> {
        private ImageView mImageView;

        @Override
        public View createView(Context context) {
            View view = LayoutInflater.from(context).inflate(R.layout.img_t, null);
            mImageView = view.findViewById(R.id.img);
            return view;
        }

        @Override
        public void onBind(Context context, int position, final String data) {
            Glide.with(context).load(data).into(mImageView);
        }
    }

    /**
     * @属性:获取屏幕高度的方法
     * @开发者:田哥哥
     * @时间:2018/8/7 14:22
     */
    public long getScollYDistance() {
        int position = linearLayoutManager.findFirstVisibleItemPosition();
        View firstVisiableChildView = linearLayoutManager.findViewByPosition(position);
        int itemHeight = firstVisiableChildView.getHeight();
        return (position) * itemHeight - firstVisiableChildView.getTop();
    }

    private void addListener() {
        scrollBanner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (images2.size() > 0) {
                    Intent intent = new Intent(context, NewsActivity.class);
                    intent.putExtra("title", images2.get(scrollBanner.getCurrentPosition() == images2.size() - 1 ? 0 : scrollBanner.getCurrentPosition() + 1).getTitle());
                    intent.putExtra("article_id", images2.get(scrollBanner.getCurrentPosition() == images2.size() - 1 ? 0 : scrollBanner.getCurrentPosition() + 1).getArticle_id());
                    startActivity(intent);
                }
            }
        });
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                HaoDanBean taobaoGuesChildtBean = todayHighlightsBeans2.get(i);
                if (taobaoGuesChildtBean != null) {
                    Bundle bundle = new Bundle();
                    bundle.putString("num_iid", taobaoGuesChildtBean.itemid);
                    bundle.putSerializable("bean", taobaoGuesChildtBean);
                    Intent intent = new Intent(context, PromotionDetailsActivity.class);
                    intent.putExtras(bundle);
                    context.startActivity(intent);
                }
            }
        });
        banner.setOnBannerListener(new OnBannerListener() {
            @Override
            public void OnBannerClick(int position) {
                if ("2".equals(images.get(position).getType())) {
                    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.taobao.taobao");
                    if (intent != null) {
                        //获取剪贴板管理器：
                        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                        // 创建普通字符型ClipData
                        ClipData mClipData = ClipData.newPlainText("Label", images.get(position).getType_value());
                        // 将ClipData内容放到系统剪贴板里。
                        cm.setPrimaryClip(mClipData);
                        startActivity(intent);
                        return;
                    } else {
                        T.showShort(context, "未安装淘宝客户端");
                    }
                } else if ("3".equals(images.get(position).getType())) {
                    Uri uri = Uri.parse(images.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } else if ("4".equals(images.get(position).getType())) {
                    Uri uri = Uri.parse(images.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                    return;
                } else if ("6".equals(images.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity2.class);
                    intent.putExtra("title", "年货节");
                    intent.putExtra("url", "");
                    startActivity(intent);
                    return;
                } else if ("7".equals(images.get(position).getType()) || "8".equals(images.get(position).getType())) {
                    hongbao();
                    return;
                } else if ("9".equals(images.get(position).getType())) {
                    Bundle bundle = new Bundle();
                    bundle.putString("num_iid", images.get(position).getType_value());
                    openActivity(PromotionDetailsActivity.class, bundle);
                    return;
                } else if ("10".equals(images.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity.class);
                    intent.putExtra("title", "拉新活动");
                    intent.putExtra("url", Constants.APP_IP + "/wap.php/Rookie/index/uid/" + SPUtils.getStringData(context, Constants.UID, ""));
                    startActivity(intent);
                }else if ("12".equals(images.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivityz.class);
                    intent.putExtra("title", "赚咖联盟");
                    intent.putExtra("url", Constants.GET_ZHUANKA_URL);
                    startActivity(intent);
                }
                if ("".equals(images.get(position).getHref())) {
                    return;
                }
                if (images.get(position).getHref() != null) {
                    Intent intent = new Intent(context, WebViewActivity.class);
                    intent.putExtra("title", images.get(position).getTitle());
                    intent.putExtra("url", images.get(position).getHref());
                    startActivity(intent);
                }
            }
        });
        banner2.setBannerPageClickListener(new MZBannerView.BannerPageClickListener() {
            @Override
            public void onPageClick(View view, int position) {
                if ("2".equals(images3.get(position).getType())) {
                    Intent intent = context.getPackageManager().getLaunchIntentForPackage("com.taobao.taobao");
                    if (intent != null) {
                        //获取剪贴板管理器：
                        ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                        // 创建普通字符型ClipData
                        ClipData mClipData = ClipData.newPlainText("Label", images3.get(position).getType_value());
                        // 将ClipData内容放到系统剪贴板里。
                        cm.setPrimaryClip(mClipData);
                        startActivity(intent);
                        return;
                    } else {
                        T.showShort(context, "未安装淘宝客户端");
                    }
                } else if ("3".equals(images3.get(position).getType())) {
                    Uri uri = Uri.parse(images3.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                } else if ("4".equals(images3.get(position).getType())) {
                    Uri uri = Uri.parse(images3.get(position).getType());
                    Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                    startActivity(intent);
                    return;
                } else if ("6".equals(images3.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity2.class);
                    intent.putExtra("title", "年货节");
                    intent.putExtra("url", "");
                    startActivity(intent);
                    return;
                } else if ("7".equals(images3.get(position).getType()) || "8".equals(images3.get(position).getType())) {
                    hongbao();
                    return;
                } else if ("9".equals(images3.get(position).getType())) {
                    Bundle bundle = new Bundle();
                    bundle.putString("num_iid", images3.get(position).getType_value());
                    openActivity(PromotionDetailsActivity.class, bundle);
                    return;
                } else if ("10".equals(images3.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivity.class);
                    intent.putExtra("title", "拉新活动");
                    intent.putExtra("url", Constants.APP_IP + "/wap.php/Rookie/index/uid/" + SPUtils.getStringData(context, Constants.UID, ""));
                    startActivity(intent);
                }else if ("12".equals(images.get(position).getType())) {
                    Intent intent = new Intent(context, WebViewActivityz.class);
                    intent.putExtra("title", "赚咖联盟");
                    intent.putExtra("url", Constants.GET_ZHUANKA_URL);
                    startActivity(intent);
                }
                if ("".equals(images3.get(position).getHref())) {
                    return;
                }
                Intent intent = new Intent(context, WebViewActivity.class);
                intent.putExtra("title", images3.get(position).getTitle());
                intent.putExtra("url", images3.get(position).getHref());
                startActivity(intent);
            }
        });
        banner.isAutoPlay(false);
        banner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    if(images.get(position).getColor()==null){
                        return;
                    }
                    homeBg.getDrawable().setTint(Color.parseColor(images.get(position).getColor()));
                    setStatusBar(Color.parseColor(images.get(position).getColor()));
                    SPUtils.saveStringData(context, "color", images.get(position).getColor());
                    refreshLayout.setPrimaryColors(Color.parseColor(images.get(position).getColor()), Color.WHITE);
                    bgHead2.setBackgroundColor(Color.parseColor(images.get(position).getColor()));
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        refreshLayout.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                switch (Home_Search) {
                    case 0:
                        if (hasdata) {
                            refreshStatus = 0;
                            indexNum++;
                            getTbkListRequst(search_sort, "必推精选", "服装");
                        } else {
                            showToast("没有更多数据了");
                            refreshLayout.finishLoadMore();
                        }
                        break;
                    case 1:
                        if (hasdata) {
                            refreshStatus = 0;
                            indexNum++;
                            getTbkListRequst(search_sort, "", search_content);
                        } else {
                            showToast("没有更多数据了");
                            refreshLayout.finishLoadMore();
                        }
                        break;
                }
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                indexNum = 1;
                min_id = "1";
                hasdata = true;
                switch (Home_Search) {
                    case 0: //首页
                        refreshStatus = 1;
                        getTbkListRequst("tk_total_sales_des", "必推精选", "服装");
                        break;
                    case 1: //搜索页
                        refreshStatus = 1;
                        getTbkListRequst(search_sort, "", search_content);
                        break;
                }
            }
        });
        homeRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (getScollYDistance() > bgHead2.getMeasuredHeight()) {
                    bgHead2.setVisibility(View.VISIBLE);
                    bgHead2.getBackground().mutate().setAlpha(255);
                } else {
                    if (getScollYDistance() == 0) {
                        bgHead2.setVisibility(View.INVISIBLE);
                        return;
                    }
                    bgHead2.setVisibility(View.VISIBLE);
                    bgHead2.getBackground().mutate().setAlpha((int) (getScollYDistance() * 1.00 * 255 / bgHead2.getMeasuredHeight()));
                }
            }
        });

        /**
         * @属性:[]是否回滚显示
         * @开发者:田哥哥
         * @时间:2018/8/7 15:48
         */
        homeRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                int screenMeasuredHeight = UIUtils.getScreenMeasuredHeight(getActivity());
                if (getScollYDistance() > (screenMeasuredHeight / 2)) {
                    rightIcon.setVisibility(View.VISIBLE);
                } else {
                    rightIcon.setVisibility(View.GONE);
                }
            }
        });
    }

    protected void setStatusBar(int color) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
            View decorView = getActivity().getWindow().getDecorView();
            getActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            getActivity().getWindow().setStatusBarColor(color);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
            WindowManager.LayoutParams localLayoutParams = getActivity().getWindow().getAttributes();
            localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
        }
        if (color == Color.WHITE) {
            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            if (isFlyme()) {
                CommonUtils.setMeizuStatusBarDarkIcon(getActivity(), true);
            } else if (isMIUI()) {
                CommonUtils.setMiuiStatusBarDarkMode(getActivity(), true);
            } else if (Build.MANUFACTURER.equalsIgnoreCase("OPPO")) {
                CommonUtils.setOPPOStatusTextColor(true, getActivity());
            } else {
            }
        } else {
            getActivity().getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
        }
    }

    /**
     * 判断手机是否是魅族
     *
     * @return
     */
    private static boolean isFlyme() {
        try {
            final Method method = Build.class.getMethod("hasSmartBar");
            return method != null;
        } catch (final Exception e) {
            return false;
        }
    }

    /**
     * 判断手机是否是小米
     *
     * @return
     */
    private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code";
    private static final String KEY_MIUI_VERSION_NAME = "ro.miui.ui.version.name";
    private static final String KEY_MIUI_INTERNAL_STORAGE = "ro.miui.internal.storage";

    private static boolean isMIUI() {
        Properties prop = new Properties();
        boolean isMIUI;
        try {
            prop.load(new FileInputStream(new File(Environment.getRootDirectory(), "build.prop")));
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        isMIUI = prop.getProperty(KEY_MIUI_VERSION_CODE, null) != null
                || prop.getProperty(KEY_MIUI_VERSION_NAME, null) != null
                || prop.getProperty(KEY_MIUI_INTERNAL_STORAGE, null) != null;
//        SPUtils.getInstance().putCacheData("isMIUI",isMIUI);//保存是否MIUI
        return isMIUI;
    }

    private void hongbao() {
        String time = String.valueOf(System.currentTimeMillis() / 1000);
        RequestParams requestParams = new RequestParams();
        requestParams.put("data_type", PddClient.data_type);
        requestParams.put("version", PddClient.version);
        requestParams.put("timestamp", time);
        requestParams.put("token", SPUtils.getStringData(context, "token", ""));
        requestParams.put("type", "hkx.UserBalanceRecord.receiveBonus");
        Map<String, String> temp = new HashMap<>();
        temp.put("data_type", PddClient.data_type);
        temp.put("version", PddClient.version);
        temp.put("timestamp", time);
        temp.put("token", SPUtils.getStringData(context, "token", ""));
        temp.put("type", "hkx.UserBalanceRecord.receiveBonus");
        String sign = PddClient.getSign1(temp);
        requestParams.put("sign", sign);
        HttpUtils.post(Constants.HONGBAO, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

            }

            @Override
            public void onStart() {
                super.onStart();
                showLoadingDialog();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                closeLoadingDialog();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject jsonObject = new JSONObject(responseString);
                    int code = jsonObject.optInt("code");
                    String msg = jsonObject.optString("msg");
                    Intent intent = new Intent(context, QdActivity.class);
                    intent.putExtra("money", jsonObject.getString("money"));
                    SPUtils.saveIntData(context, "hongbao", 1);
                    if (code == 0) {
                        intent.putExtra("mess", "新年红包已存至余额~");
                    } else {
                        intent.putExtra("mess", msg);
                    }
                    startActivity(intent);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    @Override
    protected void lazyload() {
        if (isVisible) {
            getTopCatListRequst();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
//        View decorView = getActivity().getDecorView();
//        decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        if (CaiNiaoApplication.getUserInfoBean() != null) {
            Glide.with(context).load(CaiNiaoApplication.getUserInfoBean().user_detail.avatar).dontAnimate().placeholder(R.mipmap.icon_defult_boy).error(R.mipmap.icon_defult_boy).into(imgHead);
            Glide.with(context).load(CaiNiaoApplication.getUserInfoBean().user_detail.avatar).dontAnimate().placeholder(R.mipmap.icon_defult_boy).error(R.mipmap.icon_defult_boy).into(imgHead2);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        stopTimer();
    }

    @Override
    public void onClick(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.tv_title_content://搜索
                openActivity(SearchActivity.class);
                break;
            case R.id.ll_home_one:
                openActivity(ShopMallActivity.class);
//                EventBus.getDefault().post(new MessageEvent("shequ"));
//                openActivity(ZeroBuyActivity.class);
                break;
            case R.id.ll_home_two:
                openActivity(PHBActivity.class);
                break;
            case R.id.ll_home_three:
                intent = new Intent(getActivity(), BaoYouActivity.class);
                intent.putExtra("type", "2");
                startActivity(intent);
                break;
            case R.id.ll_home_four:
                intent = new Intent(context, WebViewActivity3.class);
                intent.putExtra("title", "一键加油");
                intent.putExtra("url", jiayou+phone);
                startActivity(intent);
                break;
            case R.id.ll_home_one1:
                openActivity(ZeroBuyActivity.class);
//                EventBus.getDefault().post(new MessageEvent("shequ"));
//                openActivity(ZeroBuyActivity.class);
                break;
            case R.id.ll_home_two1:
                Bundle bundle = new Bundle();
                bundle.putString("id", "0");
                openActivity(DouActivity.class, bundle);
                break;
            case R.id.ll_home_three1:
                intent = new Intent(getActivity(), BaoYouActivity.class);
                intent.putExtra("type", "2");
                startActivity(intent);
                break;
            case R.id.ll_home_four1:
                openActivity(TqgNewActivity.class);
                break;
            case R.id.ll_home_five:
                intent = new Intent(context, WebViewActivity3.class);
                intent.putExtra("title", "天猫国际");
                intent.putExtra("url", "https://pages.tmall.com/wow/jinkou/act/zhiyingchaoshi?from=zebra:offline");
                startActivity(intent);
                break;
//                intent = new Intent(getActivity(), BaoYouActivity.class);
//                intent.putExtra("type", "2");
//                startActivity(intent);
//                break;
            case R.id.ll_home_six:
                intent = new Intent(context, WebViewActivity3.class);
                intent.putExtra("title", "天猫超市");
                intent.putExtra("url", "https://chaoshi.tmall.com/?targetPage=index");
                startActivity(intent);
//                intent = new Intent(getActivity(), BaoYouActivity.class);
//                intent.putExtra("type", "1");
//                startActivity(intent);
                break;
            case R.id.tv_right:
                openActivity(SysMessageActivity.class);
                break;
        }
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    @Override
    protected void ReceiverBroadCastMessage(String status, String result, Serializable serializable, Intent intent) {
        super.ReceiverBroadCastMessage(status, result, serializable, intent);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    /**
     * @属性:获取推荐商品列表
     * @开发者:WMM
     * @限时秒杀
     * @时间:2018/11/20 17:05
     */
    private synchronized void getTbkListRequst1(String sort, final String title, String search) {
        RequestParams requestParams = new RequestParams();
        HttpUtils.get("http://v2.api.haodanku.com/fastbuy/apikey/haodayidanku/hour_type/" + hour_type + "/min_id/1", requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            }

            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject object = new JSONObject(responseString);
                    if ("1".equals(object.getString("code"))) {
                        JSONArray array = object.getJSONArray("data");
                        todayHighlightsBeans2.clear();
                        for (int i = 0; i < array.length(); i++) {
                            todayHighlightsBeans2.add(new Gson().fromJson(array.getJSONObject(i).toString(), HaoDanBean.class));
                        }
                        highlightsAdapter2.notifyDataSetChanged();
                    } else {
                        showToast(object.getString("msg"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        });
    }

    /**
     * @属性:获取推荐商品列表
     * @开发者:WMM
     * @为你推荐
     * @时间:2018/11/20 17:05
     */
    private synchronized void getTbkListRequst(String sort, final String title, String search) {
        RequestParams requestParams = new RequestParams();
        requestParams.put("type", "1");
        requestParams.put("cid", "0");
        requestParams.put("min_id", min_id);
        HttpUtils.post(Constants.GET_NINEBY_NEW_HD, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                showToast(throwable.getMessage());
            }

            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                if (refreshLayout != null) {
                    refreshLayout.finishRefresh();
                    refreshLayout.finishLoadMore();
                }
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject object = new JSONObject(responseString);
                    if ("1".equals(object.getString("code"))) {
                        JSONArray array = object.getJSONArray("data");
                        if (min_id.equals("1")) {
                            taobaoGuesChildtBeans.clear();
                        }
                        todayHighlightsBeans.clear();
                        min_id = object.getString("min_id");
                        if (array.length() <= 0) {
                            hasdata = false;
                            return;
                        }
                        for (int i = 0; i < array.length(); i++) {
                            taobaoGuesChildtBeans.add(new Gson().fromJson(array.getJSONObject(i).toString(), HaoDanBean.class));
                        }
                        TodayHighlightsBean2 todayHighlightsBean = new TodayHighlightsBean2();
                        todayHighlightsBean.setTitle(title);
                        todayHighlightsBean.setList(taobaoGuesChildtBeans);
                        todayHighlightsBeans.add(todayHighlightsBean);
                        highlightsAdapter.notifyDataSetChanged();
                        if (array.length() <= 0) {
                            hasdata = false;
                        }
                    } else {
                        showToast(object.getString("msg"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        });
    }

    /**
     * @属性:获取顶级淘宝商品分类列表
     * @开发者:田哥哥
     * @时间:2018/7/26 15:31
     */
    private void getTopCatListRequst() {
        RequestParams requestParams = new RequestParams();
        HttpUtils.post(Constants.HOME_TAOBAOCAT_GETTOPCATLIST_URL, requestParams, new onOKJsonHttpResponseHandler<ShopTabsBean>(new TypeToken<Response<ShopTabsBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                showToast(responseString);
            }

            @Override
            public void onStart() {
                super.onStart();
            }

            @Override
            public void onFinish() {
                super.onFinish();
            }

            @Override
            public void onSuccess(int statusCode, Response<ShopTabsBean> datas) {
                if (datas.isSuccess()) {
                    List<ShopTabsChildBean> list = datas.getData().getList();
                    tabTitles.clear();
                    list.add(0, new ShopTabsChildBean("0", "精选", "", "0"));
                    tabTitles.addAll(list);
                    CommonNavigator commonNavigator = new CommonNavigator(getActivity());
                    commonNavigator.setSkimOver(true);
                    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

                        @Override
                        public int getCount() {
                            return tabTitles.size();
                        }

                        @Override
                        public IPagerTitleView getTitleView(Context context, final int index) {
                            ClipPagerTitleView clipPagerTitleView = new ClipPagerTitleView(context);
                            clipPagerTitleView.setText(tabTitles.get(index).getName());
                            clipPagerTitleView.setTextColor(getResources().getColor(R.color.black));
                            clipPagerTitleView.setClipColor(getResources().getColor(R.color.black));
                            clipPagerTitleView.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    //首页tab不需要移动
                                    if (index > 0) {
                                        Intent intent = new Intent(getActivity(), ShopActivity.class);
                                        intent.putExtra("title", "商品");
                                        intent.putExtra("index", index - 1);
                                        intent.putExtra("name", "");
                                        startActivity(intent);
                                    }
                                }
                            });
                            return clipPagerTitleView;
                        }

                        @Override
                        public IPagerIndicator getIndicator(Context context) {
                            LinePagerIndicator indicator = new LinePagerIndicator(context);
                            indicator.setMode(1);
                            indicator.setColors(getResources().getColor(R.color.black));
                            return indicator;
                        }
                    });
                    tabBar.setNavigator(commonNavigator);
                    commonNavigator = new CommonNavigator(getActivity());
                    commonNavigator.setSkimOver(true);
                    commonNavigator.setAdapter(new CommonNavigatorAdapter() {

                        @Override
                        public int getCount() {
                            return tabTitles.size();
                        }

                        @Override
                        public IPagerTitleView getTitleView(Context context, final int index) {
                            ClipPagerTitleView clipPagerTitleView = new ClipPagerTitleView(context);
                            clipPagerTitleView.setText(tabTitles.get(index).getName());
                            clipPagerTitleView.setTextColor(getResources().getColor(R.color.black));
                            clipPagerTitleView.setClipColor(getResources().getColor(R.color.black));
                            clipPagerTitleView.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    //首页tab不需要移动
                                    if (index > 0) {
                                        Intent intent = new Intent(getActivity(), ShopActivity.class);
                                        intent.putExtra("title", "商品");
                                        intent.putExtra("index", index - 1);
                                        intent.putExtra("name", "");
                                        startActivity(intent);
                                    }
                                }
                            });
                            return clipPagerTitleView;
                        }

                        @Override
                        public IPagerIndicator getIndicator(Context context) {
                            LinePagerIndicator indicator = new LinePagerIndicator(context);
                            indicator.setMode(1);
                            indicator.setColors(getResources().getColor(R.color.black));
                            return indicator;
                        }
                    });
                    tabBar2.setNavigator(commonNavigator);
                    tabTitles.remove(0);
                    indexCatAdapter.notifyDataSetChanged();
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    /**
     * banner 列表
     */
    private void getHomeADimg() {
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 3);
        HttpUtils.post(Constants.GET_BANNER, requestParams, new onOKJsonHttpResponseHandler<BannerBean>(new TypeToken<Response<BannerBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<BannerBean> datas) {
                if (datas.isSuccess()) {
                    images3.clear();
                    images3.addAll(datas.getData().getList());
                    List<String> strings = new ArrayList<>();
                    for (int i = 0; i < images3.size(); i++) {
                        strings.add(Constants.APP_IP + images3.get(i).getImg());
                    }
                    if (images3.size() <= 0) {
                        banner2.setVisibility(View.GONE);
                    } else {
                        banner2.setVisibility(View.VISIBLE);
                        banner2.setPages(strings, new MZHolderCreator<BannerViewHolder>() {
                            @Override
                            public BannerViewHolder createViewHolder() {
                                return new BannerViewHolder();
                            }
                        });
                        banner2.start();
                    }
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    /**
     * 消息通知
     */
    private void getAD() {
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 4);
        HttpUtils.post(Constants.MESSAGE_ARTICLE_GETARTICLELIST_URL, requestParams, new onOKJsonHttpResponseHandler<MessageCenterBean>(new TypeToken<Response<MessageCenterBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<MessageCenterBean> datas) {
                if (datas.isSuccess()) {
                    if (datas.getData().getList().size() <= 0) {
                        return;
                    }
                    images2.clear();
                    images2.addAll(datas.getData().getList());
                    List<String> strings = new ArrayList<>();
                    for (int i = 0; i < images2.size(); i++) {
                        strings.add(images2.get(i).getTitle());
                    }
                    if (images2.size() > 0)
                        strings.add(images2.get(0).getTitle());
                    scrollBanner.setList(strings);
                    scrollBanner.startScroll();
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    private void tankuang() {
        final AdInfo adInfo = new AdInfo();
        List<AdInfo> adInfos = new ArrayList<>();
        final AdManager adManager = new AdManager(getActivity(), adInfos);
        adInfo.setActivityImg(Constants.APP_IP + "/Public/static/images/chunjie.png");
        adInfo.setUrl("");
        adInfo.setTitle("");
        adInfos.add(adInfo);
        adManager.setOnImageClickListener(new AdManager.OnImageClickListener() {
            @Override
            public void onImageClick(View view, AdInfo advInfo) {
                hongbao();
                adManager.dismissAdDialog();
            }
        }).setOnCloseClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            }
        });
        adManager.setOverScreen(true)
                .setPageTransformer(new ZoomOutTranformer()).showAdDialog(AdConstant.ANIM_UP_TO_DOWN);
    }

    private void getIndexIcon() {
        RequestParams requestParams = new RequestParams();
        HttpUtils.post(Constants.SET, requestParams, new onOKJsonHttpResponseHandler<SetBean>(new TypeToken<Response<SetBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<SetBean> datas) {
                if (datas.isSuccess()) {
                    for (int i = 0; i < datas.getData().moduleList.size(); i++) {
                        if ("Y".equals(datas.getData().moduleList.get(i).is_index_show)) {
                            homeItems.add(datas.getData().moduleList.get(i));
                            if ("34".equals(datas.getData().moduleList.get(i).id)){
                                jiayou = datas.getData().moduleList.get(i).url;
                            }
                        }
                    }
                    int count = (homeItems.size() - 1) / 10 + 1;
                    for (int i = 0; i < count; i++) {
                        RadioButton rb = (RadioButton) LayoutInflater.from(context).inflate(R.layout.item_page_group, null);
                        rb.setId(i);
                        if (i == 0) {
                            rb.setChecked(true);
                        }
                        page_rg.addView(rb);
                    }
                    homeIconAdapter.notifyDataSetChanged();
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }
    /**
     * 获取用户信息
     */
    private void getUserMsg() {
//        if (!CommonUtils.isNetworkAvailable()) {
//            showToast(getResources().getString(R.string.error_network));
//            return;
//        }
        RequestParams params = new RequestParams();
        HttpUtils.post(Constants.GET_USER_MSG, params, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {

            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject jsonObject = new JSONObject(responseString);
                    int code = jsonObject.optInt("code");

                    //返回码说明
                    String msg = jsonObject.optString("msg");
                    String data = jsonObject.optString("data");
                    if (0 == code) {
                        if (!TextUtils.isEmpty(data)) {//GSON对数字都当做double解析
                            Gson gson = new Gson();
                            userBean = gson.fromJson(data.trim(), UserInfoBean.class);
                            Glide.with(context).load(userBean.user_detail.avatar).dontAnimate().placeholder(R.mipmap.icon_defult_boy).error(R.mipmap.icon_defult_boy).into(imgHead);
                            Glide.with(context).load(userBean.user_detail.avatar).dontAnimate().placeholder(R.mipmap.icon_defult_boy).error(R.mipmap.icon_defult_boy).into(imgHead2);
                            phone = userBean.user_msg.phone;
                        }
                    }

                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

        });

    }
    private void getBanner() {
        RequestParams requestParams = new RequestParams();
        requestParams.put("cat_id", 1);
        HttpUtils.post(Constants.GET_BANNER, requestParams, new onOKJsonHttpResponseHandler<BannerBean>(new TypeToken<Response<BannerBean>>() {
        }) {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//                showToast(throwable.getMessage());
            }

            @Override
            public void onSuccess(int statusCode, Response<BannerBean> datas) {
                if (datas.isSuccess()) {
                    images.clear();
                    images.addAll(datas.getData().getList());
                    List<String> strings = new ArrayList<>();
                    for (int i = 0; i < images.size(); i++) {
                        strings.add(Constants.APP_IP + images.get(i).getImg());
                        if ("15".equals(images.get(i).getId()) && SPUtils.getIntData(context, "hongbao", 0) != 1) {
                            //有红包，并且没领过
//                            tankuang();
                        }
                    }
                    banner.isAutoPlay(true);
                    banner.setDelayTime(5000);
                    banner.update(strings);
                } else {
                    showToast(datas.getMsg());
                }
            }
        });
    }

    @OnClick({R.id.tv_title_content2, R.id.tv_right2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_title_content2:
                openActivity(SearchActivity.class);
                break;
            case R.id.tv_right2:
                openActivity(SysMessageActivity.class);
                break;
        }
    }

}
